package com.doit.day01;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import redis.clients.jedis.Jedis;

public class _04_模拟生产队列练习 {
    public static void main(String[] args) throws InterruptedException {

        Jedis jedis = new Jedis("linux01",6379);

        while (true){
            String task = RandomStringUtils.randomAlphabetic(10);
            System.out.println("42期的大哥们，正在生产代码任务......"+task);
            jedis.lpush("producer_task",task);

            Thread.sleep(RandomUtils.nextInt(50,250));

            //将生产队列中的任务，放到缓冲区中
            String cache_task = jedis.rpoplpush("producer_task", "cache_task");
            System.out.println("任务已经加入到缓冲区"+cache_task);

            if (jedis.llen("cache_task") >10){
                Thread.sleep(3000);
            }

        }





    }
}
